<?php
include_once ("../Login/databaseconnection.php");
$q=$_GET["q"];
$hint="";
$name=explode(",",$q);
$nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
$School_Id=$row['School_Id'];
}
$hint=$hint.'<select name="Exam_Name" onChange="getExaSubject(this.value)">';
   if(isset($_POST['SaveChanges']))
	  {
	   	 $Exam_Name=$_SESSION['Exa_Name'];	    
		 unset($_SESSION['Exa_Name']);
	  }
	  if($Exam_Name!="")
	  {
		 $hint=$hint.'<option value="'.$Exam_Name.'">'.$Exam_Name.'</option>';
	  }
	  else
	  {
	  $hint=$hint.'<option value="Select One">Select One</option>';
	  }
			if($School_Id!="")
		{
			$exa=mysql_query("SELECT DISTINCT(Exam_Name) FROM exam WHERE School_Id='$School_Id'");
		}
		if($School_Id=="")
		{
		  $exa=mysql_query("SELECT DISTINCT(Exam_Name) FROM exam");
		}
 while($row=mysql_fetch_array($exa))
  {
	 $Exa_Name=$row['Exam_Name'];
if($Exam_Name!=$Exa_Name)
{
	  $hint=$hint.'<option value="'.$Exa_Name.'">'.$Exa_Name.'</option>';
  }
  }
      $hint=$hint.'</select>';
	  if($hint=="")
{
$response=$response.'<select name="Exam_Name" onChange="getExaSubject(this.value)">';
 $response=$response.'<option value="Select One">Select One</option>';
	 $e=mysql_query("SELECT DISTINCT(Exam_Name) FROM exam");
	  
  while($row=mysql_fetch_array($e))
  {
   $e_Name=$row['Exam_Name'];
	$response=$response.'<option value="'.$e_Name.'">'.$e_Name.'</option>';
  }
$response=$response.'</select>';
}
else
{
$response=$hint;
}
echo $response;
?>